home *** CD-ROM | disk | FTP | other *** search
/ Practical Algorithms for Image Analysis / Practical Algorithms for Image Analysis.iso / LIBIP / FFT2D.C < prev    next >
C/C++ Source or Header  |  1999-09-11  |  2KB  |  67 lines

  1. /* 
  2.  * fft2d.c
  3.  * 
  4.  * Practical Algorithms for Image Analysis
  5.  * 
  6.  * Copyright (c) 1997, 1998, 1999 MLMSoftwareGroup, LLC
  7.  */
  8.  
  9. #include <stdlib.h>
  10. #include <malloc.h>
  11. #include <math.h>
  12. #include <stdio.h>
  13.  
  14. /*
  15.  * fft2d()
  16.  *   DESCRIPTION:
  17.  *     fft2d performs 2-dimensional FFT on square image file
  18.  *     using Kernel as the kernel and
  19.  *     placing the convolved image in ImageOut
  20.  *   ARGUMENTS:
  21.  *     imageReal(float **) pointer to real array
  22.  *     imgImag(float **) pointer to imaginary array
  23.  *     nRow, nCol(long) number of rows and columns for real and img arrays
  24.  *                      must be power of 2
  25.  *     flag(short)      flag=-1 forward transform
  26.  *                              flag=1 reverse transform
  27.  *   RETURN VALUE:
  28.  *     none
  29.  */
  30.  
  31. void
  32. fft2d (imgReal, imgImag, nRow, nCol, flag)
  33.      float **imgReal, **imgImag;  /* real and imaginary image arrays */
  34.      register long nRow, nCol;  /* no. rows and columns */
  35.      short flag;                /* forward transform if -1; reverse if 1 */
  36. {
  37.   register int x, y;
  38.   float *tempReal, *tempImag;   /* temporary complex vectors */
  39.   int fft ();                   /* performs 1-D FFT */
  40.  
  41. /* allocate space for temporary vectors */
  42.   if ((tempReal = (float *) calloc (nRow, sizeof (float))) == NULL)
  43.       exit (1);
  44.   if ((tempImag = (float *) calloc (nRow, sizeof (float))) == NULL)
  45.       exit (2);
  46.  
  47. /* perform row-wise FFTs */
  48.   for (y = 0; y < nRow; y++) {
  49.     fft (nCol, imgReal[y], imgImag[y], flag);
  50.   }
  51.  
  52. /* perform column-wise FFTs */
  53.   for (x = 0; x < nCol; x++) {
  54.     for (y = 0; y < nRow; y++) {
  55.       tempReal[y] = imgReal[y][x];
  56.       tempImag[y] = imgImag[y][x];
  57.     }
  58.     fft (nRow, tempReal, tempImag, flag);
  59.     for (y = 0; y < nRow; y++) {
  60.       imgReal[y][x] = tempReal[y];
  61.       imgImag[y][x] = tempImag[y];
  62.     }
  63.   }
  64.  
  65.   return;
  66. }
  67.